<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<% 
	String password = session.getAttribute("password").toString();
	String hospitalID = session.getAttribute("hosploginid").toString();
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="favicon.ico">
<link href="${pageContext.request.contextPath }/bootstrapStyle/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrapStyle/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrapStyle/css/animate.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrapStyle/css/style.min.css?v=4.0.0" rel="stylesheet">
<link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap/css/bundled.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/bootstrap/css/jquery-confirm.css"/>
<title>修改密码界面</title>
</head>
<body>
	<div class=".container" style="margin-top:100px;width:250%;">
		<c:if test="${info!=null }">
			<div class="alert alert-info">
	        	密码修改<c:if test="${info==success }">成功！！！</c:if><c:if test="${info==error }">失败！！！</c:if>
			</div>
		</c:if>
	<form class="form-horizontal" id="formSubmit">
	  <div class="form-group">
	    <label for="oldpass" class="col-sm-2 control-label">旧密码</label>
	    <div class="col-sm-10">
	      <input type="password" class="form-control" style="width:250px;" id="oldpass" placeholder="旧密码"><span id="oldpassTip" style="display:none;color:red;"></span>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="newpass" class="col-sm-2 control-label">新密码</label>
	    <div class="col-sm-10">
	      <input type="password" class="form-control" style="width:250px;" id="newpass" placeholder="新密码"><span id="newpassTip" style="display:none;color:red;"></span>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="newpassAgain" class="col-sm-2 control-label">再次确认新密码</label>
	    <div class="col-sm-10">
	      <input type="password" class="form-control" style="width:250px;" id="newpassAgain" placeholder="重复新密码"><span id="newpassAgainTip" style="display:none;color:red;"></span>
	    </div>
	  </div>
	  <div class="form-group">
	    <label class="col-sm-2 control-label">  </label>
	 	 <button type="submit" class="btn btn-primary" id="submit" style="text-align:center;">确认修改</button>
	  </div>
	</form>
</div>
<!-- <div id="modifySuccess" class="alert alert-success alert-dismissable" style="width:50%;margin-left:40%;display:none;">
  <strong>Success!</strong> 你已成功修改密码！
</div> -->
</body>
<script src="${pageContext.request.contextPath }/bootstrapStyle/js/bundled.js"></script>
<script src="${pageContext.request.contextPath }/bootstrapStyle/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath }/bootstrapStyle/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath }/bootstrapStyle/js/jquery-confirm.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	var error = false;
	$("#oldpass").blur(function(){
		var oldpass = $("#oldpass").val();
		if(oldpass =='') {
			showError('oldpass', '密码不能为空');
			error = true;
			return;
		}else if(oldpass != "<%=password%>") {
			showError('oldpass', '旧密码输入不正确');
			error = true;
			return;
		}else {
			$("#oldpass").css({"border-color":"green"});
			$("#oldpassTip").css({"display":"none"});
			error = false;
			return;
		}
	});
	$("#newpass").blur(function(){
		var newpass = $("#newpass").val();
		if(newpass == '') {
			showError('newpass', '新密码不能为空');
			error = true;
		}else {
			$("#newpass").css({"border-color":"green"});
			$("#newpassTip").css({"display":"none"});
			error = false;
		}
	});
	$("#newpassAgain").blur(function(){
		var newpass = $("#newpass").val();
		if(newpass == '') {
			showError('newpass', '新密码不能为空');
			error = true;
			return;
		}
		var newpassAgain = $("#newpassAgain").val();
		if(newpassAgain != newpass) {
			showError('newpassAgain', '与输入的新密码不一致');
			error = true;
			return;
		}else {
			$("#newpassAgain").css({"border-color":"green"});
			$("#newpassAgainTip").css({"display":"none"});
			error = false;
			return;
		}
	});
	$('#formSubmit').submit(function(event) {
		$("#oldpass").blur();
		$("#newpass").blur();
		$("#newpassAgain").blur();
		var newpass = $("#newpass").val();
		if(!error){
			$.ajax({
	            type: "post",
	            url:"${pageContext.request.contextPath}/Main/changePasSubmit.action",
	            contentType:"application/json;charset=utf-8",
	            data:'{"hosploginpwd":"'+newpass+'","hosploginid":"<%=hospitalID%>"}',
	            success: function (data) {
	            	if(data==1){
	            		$.alert('提示');
	            		$.alert({
	            		    title: '提示!',
	            		    content: "密码修改成功！",
	            		    type: 'green',
	            		    typeAnimated: true,
	            		    buttons:{确定:function(){window.location.href="${pageContext.request.contextPath}/Main/changePas.action";}}
	            		});
	            	}else{
	            		$.alert({
	            		    title: '提示!',
	            		    content: "密码修改失败，重试！",
	            		    type: 'red',
	            		    typeAnimated: true,
	            		    buttons:{确定:function(){}}
	            		});
	            	}
	            	//window.location.href="${pageContext.request.contextPath}/Main/changePas.action";
	            },error: function(XMLHttpRequest,textStatus,errorThrown) {
	                alert("url请求失败！！"+XMLHttpRequest.status+"<hr>"+errorThrown+"<hr>"+textStatus);
	            }
	        });
		}
		event.preventDefault();
		return false;
    });
});
function showError(formSpan, errorText) {
	$("#" + formSpan).css({"border-color":"red"});
	$("#" + formSpan + "Tip").empty();
	$("#" + formSpan + "Tip").append(errorText);;
	$("#" + formSpan + "Tip").css({"display":"inline"});
}
</script>
</html>